package com.edu.exam.enums.exam;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 考试类型枚举
 */
public enum ExamType implements BaseEnum {

    // === 考试阶段类型 ===
    MIDTERM("MIDTERM", "期中考试", 1),
    FINAL("FINAL", "期末考试", 2),
    MONTHLY("MONTHLY", "月度考试", 3),
    WEEKLY("WEEKLY", "周测考试", 4),
    QUIZ("QUIZ", "随堂测验", 5),

    // === 考试性质类型 ===
    REGULAR("REGULAR", "正常考试", 10),
    MAKEUP("MAKEUP", "补考", 11),
    RETAKE("RETAKE", "重考", 12),
    RESIT("RESIT", "重修考试", 13),
    DEFERRED("DEFERRED", "延考", 14),
    GRADUATION_CLEARANCE("GRADUATION_CLEARANCE", "毕业清考", 15),

    // === 考试形式类型 ===
    PRACTICAL("PRACTICAL", "实践考试", 20),
    PROJECT("PROJECT", "项目考试", 21),
    THESIS("THESIS", "论文答辩", 22),

    // === 考试方式类型 ===
    COMPUTER_BASED("COMPUTER_BASED", "计算机考试", 30),
    PAPER_BASED("PAPER_BASED", "纸质考试", 31),
    MIXED("MIXED", "混合模式", 32),
    ORAL("ORAL", "口试", 33),
    ONLINE("ONLINE", "在线考试", 34),
    OFFLINE("OFFLINE", "线下考试", 35),

    // === 特殊考试类型 ===
    SPECIAL("SPECIAL", "特殊考试", 40),
    QUALIFICATION("QUALIFICATION", "资格考试", 41),
    PLACEMENT("PLACEMENT", "分级考试", 42),
    OTHER("OTHER", "其他", 99);

    private final String code;
    private final String description;
    private final int order;

    ExamType(String code, String description, int order) {
        this.code = code;
        this.description = description;
        this.order = order;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    public int getOrder() {
        return order;
    }

    /**
     * 根据编码查找枚举值
     */
    public static ExamType fromCode(String code) {
        if (code == null || code.trim().isEmpty()) {
            return REGULAR; // 默认正常考试
        }

        for (ExamType value : values()) {
            if (value.getCode().equals(code)) {
                return value;
            }
        }
        return REGULAR;
    }

    /**
     * 根据描述查找枚举值
     *
     * @param description 显示描述
     * @return 对应的枚举值，null如果未找到
     */
    public static ExamType fromDescription(String description) {
        if (description == null || description.trim().isEmpty()) {
            return null;
        }

        for (ExamType value : values()) {
            if (value.getDescription().equals(description)) {
                return value;
            }
        }
        return null;
    }

    @Override
    public String toString() {
        return this.code + "(" + this.description + ")";
    }
}